#include "serialportthread.h"
extern void printfCharArray(const char *name,unsigned char *pBuf,int len);

SerialPortThread::SerialPortThread()
{
    myCom = new QSerialPort();
    myCom->setPortName("/dev/ttyAMA0");
    myCom->open(QIODevice::ReadWrite);
    myCom->setBaudRate(QSerialPort::Baud115200);
    myCom->setDataBits(QSerialPort::Data8);
    myCom->setParity(QSerialPort::NoParity);
    myCom->setStopBits(QSerialPort::OneStop);
    myCom->setFlowControl(QSerialPort::NoFlowControl);
    stopped = false;
}
void SerialPortThread::run()
{
    char buf[10]={0};
    stopped = false;
    //myCom->flush();
    myCom->clear();
    while(!stopped)
    {
        if(myCom->waitForReadyRead(1000))
        {
            memset(buf,0,10);
            int len = myCom->read(buf,10);
            myCom->clear();
            qDebug("rlen=%d",len);
            printfCharArray("buf",(unsigned char*)buf,len);
        }
        //sleep(1);
    }
    qDebug("线程退出");

}
void SerialPortThread::stop()
{
    stopped = true;
}
void SerialPortThread::writeData()
{
    int len=myCom->write("test",4);
    qDebug("len=%d",len);
}
SerialPortThread::~SerialPortThread()
{
    myCom->close();
   delete myCom;
}
